﻿
// MailSoltCltView.cpp: CMailSoltCltView 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MailSoltClt.h"
#endif

#include "MailSoltCltDoc.h"
#include "MailSoltCltView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMailSoltCltView

IMPLEMENT_DYNCREATE(CMailSoltCltView, CView)

BEGIN_MESSAGE_MAP(CMailSoltCltView, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_COMMAND(IDM_SOLT_SEND, &CMailSoltCltView::OnSoltSend)
END_MESSAGE_MAP()

// CMailSoltCltView 构造/析构

CMailSoltCltView::CMailSoltCltView() noexcept
{
	// TODO: 在此处添加构造代码

}

CMailSoltCltView::~CMailSoltCltView()
{
}

BOOL CMailSoltCltView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CMailSoltCltView 绘图

void CMailSoltCltView::OnDraw(CDC* /*pDC*/)
{
	CMailSoltCltDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此处为本机数据添加绘制代码
}


// CMailSoltCltView 打印

BOOL CMailSoltCltView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CMailSoltCltView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CMailSoltCltView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}


// CMailSoltCltView 诊断

#ifdef _DEBUG
void CMailSoltCltView::AssertValid() const
{
	CView::AssertValid();
}

void CMailSoltCltView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMailSoltCltDoc* CMailSoltCltView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMailSoltCltDoc)));
	return (CMailSoltCltDoc*)m_pDocument;
}
#endif //_DEBUG


// CMailSoltCltView 消息处理程序


void CMailSoltCltView::OnSoltSend()
{
	// TODO: 在此添加命令处理程序代码
	HANDLE hMailSlot;
	hMailSlot = CreateFile("\\\\.\\mailslot\\MyMailSlot", GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (INVALID_HANDLE_VALUE == hMailSlot) {
		MessageBox("打开油槽失败！");
		return;
	}

	char buf[] = "http://www.baidu.com";
	DWORD dwFile;
	if (!WriteFile(hMailSlot, buf, strlen(buf) + 1, &dwFile, NULL)) {
		MessageBox("写入数据失败！");
		CloseHandle(hMailSlot);
		return;
	}
	CloseHandle(hMailSlot);
}
